package pattern2;

///**
// * @author wdl
// */
//public class CashContext {
//    private CashSuper cashSuper;
//
//    /**
//     * 通过构造方法传入具体的收费策略
//     * @param cashSuper 收费策略
//     */
//    public CashContext(CashSuper cashSuper) {
//        this.cashSuper = cashSuper;
//    }
//
//    /**
//     * 根据不同收费策略获得结构
//     * @param money 输入金额
//     * @return 返回具体收费策略的收费金额
//     */
//    public double getResult(double money) {
//        return cashSuper.acceptCash(money);
//    }
//}

/**
 * 结合简单工厂的Context类
 *
 * @author wdl
 */
public class CashContext {
    private CashSuper cashSuper = null;

    public CashContext(int type) {
        switch (type) {
            //普通收费
            case 1:
                cashSuper = new CashNormal();
                break;
            //8折优惠
            case 2:
                cashSuper = new CashRate(0.8);
                break;
            //满300-100
            case 3:
                cashSuper = new CashReturn(300, 100);
                break;
            default:
        }
    }

    public double getResult(double money) {
        return cashSuper.acceptCash(money);
    }
}